/**
 * Copyright (c) 2014, 2016 itemis AG (http://www.itemis.eu) and others.
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0.
 * 
 * SPDX-License-Identifier: EPL-2.0
 */
package org.eclipse.xtend.core.tests.compiler;

import org.eclipse.xtend2.lib.StringConcatenation;
import org.junit.Test;

/**
 * @author Sebastian Zarnekow - Initial contribution and API
 */
@SuppressWarnings("all")
public class NestedClassCompilerTest extends AbstractXtendCompilerTest {
  @Test
  public void testPlain() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class C {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("static class X {}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("X x");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("@SuppressWarnings(\"all\")");
    _builder_1.newLine();
    _builder_1.append("public class C {");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public static class X {");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("private C.X x;");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    this.assertCompilesTo(_builder, _builder_1);
  }

  @Test
  public void testAbstractNestedClass() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class C {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("abstract static class X {}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("@SuppressWarnings(\"all\")");
    _builder_1.newLine();
    _builder_1.append("public class C {");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public static abstract class X {");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    this.assertCompilesTo(_builder, _builder_1);
  }

  @Test
  public void testGetSuper_01() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class C {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def void m2(A a) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("a.super.m");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.append("class A {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def B getSuper() {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.append("class B {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def void m() {}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("@SuppressWarnings(\"all\")");
    _builder_1.newLine();
    _builder_1.append("public class C {");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public void m2(final A a) {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("a.getSuper().m();");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    this.assertCompilesTo(_builder, _builder_1);
  }

  @Test
  public void testGetSuper_02() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class C {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def void m2(A it) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("super.toString");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.append("class A {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def Object getSuper() {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("@SuppressWarnings(\"all\")");
    _builder_1.newLine();
    _builder_1.append("public class C {");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public void m2(final A it) {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("super.toString();");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    this.assertCompilesTo(_builder, _builder_1);
  }

  @Test
  public void testOverloads() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class A {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("static class B {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("def void m(CharSequence c) {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("m(\'\')");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def static void m(String s) {}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("@SuppressWarnings(\"all\")");
    _builder_1.newLine();
    _builder_1.append("public class A {");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public static class B {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("public void m(final CharSequence c) {");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("this.m(\"\");");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public static void m(final String s) {");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    this.assertCompilesTo(_builder, _builder_1);
  }

  @Test
  public void testOverloadsOuterChosen() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class A {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("static class B {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("def void m(int i) {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("m(\'\')");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def static void m(String s) {}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("@SuppressWarnings(\"all\")");
    _builder_1.newLine();
    _builder_1.append("public class A {");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public static class B {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("public void m(final int i) {");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("A.m(\"\");");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public static void m(final String s) {");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    this.assertCompilesTo(_builder, _builder_1);
  }

  @Test
  public void testDeeplyNested() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class A {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("static interface B {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("class C {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("A a");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("B b");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("C c");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("D d");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("static class D {");
    _builder.newLine();
    _builder.append("\t\t\t\t");
    _builder.append("A a");
    _builder.newLine();
    _builder.append("\t\t\t\t");
    _builder.append("B b = new A.B {}");
    _builder.newLine();
    _builder.append("\t\t\t\t");
    _builder.append("C c = new C");
    _builder.newLine();
    _builder.append("\t\t\t\t");
    _builder.append("D d = new B.C.D {}");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("A a");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("B b = new B {}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("B.C c");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("B.C.D d");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("@SuppressWarnings(\"all\")");
    _builder_1.newLine();
    _builder_1.append("public class A {");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public interface B {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("class C {");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("public static class D {");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("private A a;");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("private A.B b = new A.B() {");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("};");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("private A.B.C c = new A.B.C();");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("private A.B.C.D d = new A.B.C.D() {");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("};");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("private A a;");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("private A.B b;");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("private A.B.C c;");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("private A.B.C.D d;");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("private A a;");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("private A.B b = new A.B() {");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("};");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("private A.B.C c;");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("private A.B.C.D d;");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    this.assertCompilesTo(_builder, _builder_1);
  }

  @Test
  public void testDeeplyNestedWithDollarSyntax() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class A {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("static interface B {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("class C {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("A a");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("B b");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("C c");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("D d");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("static class D {");
    _builder.newLine();
    _builder.append("\t\t\t\t");
    _builder.append("A a");
    _builder.newLine();
    _builder.append("\t\t\t\t");
    _builder.append("B b = new A$B {}");
    _builder.newLine();
    _builder.append("\t\t\t\t");
    _builder.append("C c = new C");
    _builder.newLine();
    _builder.append("\t\t\t\t");
    _builder.append("D d = new B$C$D {}");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("A a");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("B b = new B {}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("B$C c = new B$C {}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("B$C$D d = new B$C$D");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("@SuppressWarnings(\"all\")");
    _builder_1.newLine();
    _builder_1.append("public class A {");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public interface B {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("class C {");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("public static class D {");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("private A a;");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("private A.B b = new A.B() {");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("};");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("private A.B.C c = new A.B.C();");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("private A.B.C.D d = new A.B.C.D() {");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("};");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("private A a;");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("private A.B b;");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("private A.B.C c;");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("private A.B.C.D d;");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("private A a;");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("private A.B b = new A.B() {");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("};");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("private A.B.C c = new A.B.C() {");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("};");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("private A.B.C.D d = new A.B.C.D();");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    this.assertCompilesTo(_builder, _builder_1);
  }

  @Test
  public void testOuterMemberAccess() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class C {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("static class X {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("new(C c) {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("c.m");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("private def void m() {}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("@SuppressWarnings(\"all\")");
    _builder_1.newLine();
    _builder_1.append("public class C {");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public static class X {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("public X(final C c) {");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("c.m();");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("private void m() {");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    this.assertCompilesTo(_builder, _builder_1);
  }

  @Test
  public void testSiblingAccess() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class C {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("static class X {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("new(Y y) {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("y.m");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("private static class Y {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("private def void m() {}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("@SuppressWarnings(\"all\")");
    _builder_1.newLine();
    _builder_1.append("public class C {");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public static class X {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("public X(final C.Y y) {");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("y.m();");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("private static class Y {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("private void m() {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    this.assertCompilesTo(_builder, _builder_1);
  }

  @Test
  public void testNestedInterface() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class C {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("interface I {}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("@SuppressWarnings(\"all\")");
    _builder_1.newLine();
    _builder_1.append("public class C {");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public interface I {");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    this.assertCompilesTo(_builder, _builder_1);
  }

  @Test
  public void testNestedEnum() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class C {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("private static enum E {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("VAL");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("@SuppressWarnings(\"all\")");
    _builder_1.newLine();
    _builder_1.append("public class C {");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("private enum E {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("VAL;");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    this.assertCompilesTo(_builder, _builder_1);
  }

  @Test
  public void testNestedAnnotation() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class C {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("package annotation A {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("String value = \'\'");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("@SuppressWarnings(\"all\")");
    _builder_1.newLine();
    _builder_1.append("public class C {");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("@interface A {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("public String value() default \"\";");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    this.assertCompilesTo(_builder, _builder_1);
  }

  @Test
  public void testBugNotAnEnclosingInstance_01() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class Account {");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("def Iterable<Boolean> transferAReq(int _amount, Account _account) {");
    _builder.newLine();
    _builder.append("        ");
    _builder.append("return new Iterable<Boolean>() {");
    _builder.newLine();
    _builder.append("            ");
    _builder.append("val dis = this;");
    _builder.newLine();
    _builder.append("            ");
    _builder.append("val depositExceptionHandler = new com.google.common.collect.AbstractIterator<Boolean>() {");
    _builder.newLine();
    _builder.append("                ");
    _builder.append("override Boolean computeNext() {");
    _builder.newLine();
    _builder.append("                    ");
    _builder.append("return false;");
    _builder.newLine();
    _builder.append("                ");
    _builder.append("}");
    _builder.newLine();
    _builder.append("            ");
    _builder.append("};");
    _builder.newLine();
    _builder.append("            ");
    _builder.append("override java.util.Iterator<Boolean> iterator() {");
    _builder.newLine();
    _builder.append("                ");
    _builder.append("send([dis.processAsyncResponse(true)]);");
    _builder.newLine();
    _builder.append("                ");
    _builder.append("null");
    _builder.newLine();
    _builder.append("            ");
    _builder.append("}");
    _builder.newLine();
    _builder.append("            ");
    _builder.append("def void send((Object)=>void p) {}");
    _builder.newLine();
    _builder.append("            ");
    _builder.append("def void processAsyncResponse(boolean o) {}");
    _builder.newLine();
    _builder.append("        ");
    _builder.append("};");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("}");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("def Object depositSReq(int amount) {}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("import com.google.common.collect.AbstractIterator;");
    _builder_1.newLine();
    _builder_1.append("import java.util.Iterator;");
    _builder_1.newLine();
    _builder_1.append("import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("@SuppressWarnings(\"all\")");
    _builder_1.newLine();
    _builder_1.append("public class Account {");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public Iterable<Boolean> transferAReq(final int _amount, final Account _account) {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("abstract class __Account_1 implements Iterable<Boolean> {");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("final __Account_1 _this__Account_1 = this;");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("__Account_1 dis;");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("AbstractIterator<Boolean> depositExceptionHandler;");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("public abstract void send(final Procedure1<? super Object> p);");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("public abstract void processAsyncResponse(final boolean o);");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("return new __Account_1() {");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("{");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("dis = this;");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("depositExceptionHandler = new AbstractIterator<Boolean>() {");
    _builder_1.newLine();
    _builder_1.append("          ");
    _builder_1.append("@Override");
    _builder_1.newLine();
    _builder_1.append("          ");
    _builder_1.append("public Boolean computeNext() {");
    _builder_1.newLine();
    _builder_1.append("            ");
    _builder_1.append("return Boolean.valueOf(false);");
    _builder_1.newLine();
    _builder_1.append("          ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("};");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("@Override");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("public Iterator<Boolean> iterator() {");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("Object _xblockexpression = null;");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("{");
    _builder_1.newLine();
    _builder_1.append("          ");
    _builder_1.append("final Procedure1<Object> _function = (Object it) -> {");
    _builder_1.newLine();
    _builder_1.append("            ");
    _builder_1.append("this.dis.processAsyncResponse(true);");
    _builder_1.newLine();
    _builder_1.append("          ");
    _builder_1.append("};");
    _builder_1.newLine();
    _builder_1.append("          ");
    _builder_1.append("this.send(_function);");
    _builder_1.newLine();
    _builder_1.append("          ");
    _builder_1.append("_xblockexpression = null;");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("return ((Iterator<Boolean>)_xblockexpression);");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("public void send(final Procedure1<? super Object> p) {");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("public void processAsyncResponse(final boolean o) {");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("};");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public Object depositSReq(final int amount) {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("return null;");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    this.assertCompilesTo(_builder, _builder_1);
  }

  @Test
  public void testBugNotAnEnclosingInstance_02() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class C {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def void m1(String s) {}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def void m2() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("new Object() {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("def void m1(int i) {}");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("def void m2() {");
    _builder.newLine();
    _builder.append("\t\t\t\t");
    _builder.append("val I i = [");
    _builder.newLine();
    _builder.append("\t\t\t\t\t");
    _builder.append("m1(1)");
    _builder.newLine();
    _builder.append("\t\t\t\t\t");
    _builder.append("m1(\'\')");
    _builder.newLine();
    _builder.append("\t\t\t\t");
    _builder.append("]");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("interface I {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("def void m1(int i)");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("@SuppressWarnings(\"all\")");
    _builder_1.newLine();
    _builder_1.append("public class C {");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public interface I {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("void m1(final int i);");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public void m1(final String s) {");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public void m2() {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("abstract class __C_1 {");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("final __C_1 _this__C_1 = this;");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("public abstract void m1(final int i);");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("public abstract void m2();");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("new __C_1() {");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("public void m1(final int i) {");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("public void m2() {");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("final C.I _function = (int it) -> {");
    _builder_1.newLine();
    _builder_1.append("          ");
    _builder_1.append("this.m1(1);");
    _builder_1.newLine();
    _builder_1.append("          ");
    _builder_1.append("C.this.m1(\"\");");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("};");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("final C.I i = _function;");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("};");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    this.assertCompilesTo(_builder, _builder_1);
  }

  @Test
  public void testBugNotAnEnclosingInstance_03() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class C {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def void m1(String s) {}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def void m2() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("new Object() {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("def void m1(int i) {}");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("def void m2() {");
    _builder.newLine();
    _builder.append("\t\t\t\t");
    _builder.append("val I i = new I() {");
    _builder.newLine();
    _builder.append("\t\t\t\t\t");
    _builder.append("override void m1() {");
    _builder.newLine();
    _builder.append("\t\t\t\t\t\t");
    _builder.append("m1(1)");
    _builder.newLine();
    _builder.append("\t\t\t\t\t\t");
    _builder.append("m1(\'\')");
    _builder.newLine();
    _builder.append("\t\t\t\t\t\t");
    _builder.append("m1()");
    _builder.newLine();
    _builder.append("\t\t\t\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t\t\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("interface I {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("def void m1()");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("@SuppressWarnings(\"all\")");
    _builder_1.newLine();
    _builder_1.append("public class C {");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public interface I {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("void m1();");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public void m1(final String s) {");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public void m2() {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("abstract class __C_1 {");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("final __C_1 _this__C_1 = this;");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("public abstract void m1(final int i);");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("public abstract void m2();");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("new __C_1() {");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("public void m1(final int i) {");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("public void m2() {");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("final C.I i = new C.I() {");
    _builder_1.newLine();
    _builder_1.append("          ");
    _builder_1.append("@Override");
    _builder_1.newLine();
    _builder_1.append("          ");
    _builder_1.append("public void m1() {");
    _builder_1.newLine();
    _builder_1.append("            ");
    _builder_1.append("_this__C_1.m1(1);");
    _builder_1.newLine();
    _builder_1.append("            ");
    _builder_1.append("C.this.m1(\"\");");
    _builder_1.newLine();
    _builder_1.append("            ");
    _builder_1.append("this.m1();");
    _builder_1.newLine();
    _builder_1.append("          ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("};");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("};");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    this.assertCompilesTo(_builder, _builder_1);
  }

  @Test
  public void testBugNotAnEnclosingInstance_04() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class C {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def void m1(String s) {}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def void m2() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("new D() {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("def void m2() {");
    _builder.newLine();
    _builder.append("\t\t\t\t");
    _builder.append("val I i = [");
    _builder.newLine();
    _builder.append("\t\t\t\t\t");
    _builder.append("self.m1(1)");
    _builder.newLine();
    _builder.append("\t\t\t\t\t");
    _builder.newLine();
    _builder.append("\t\t\t\t\t");
    _builder.append("m1(1)");
    _builder.newLine();
    _builder.append("\t\t\t\t\t");
    _builder.append("this.m1(1)");
    _builder.newLine();
    _builder.append("\t\t\t\t\t");
    _builder.append("m1(\'\')");
    _builder.newLine();
    _builder.append("\t\t\t\t\t");
    _builder.append("C.this.m1(\'\')");
    _builder.newLine();
    _builder.append("\t\t\t\t\t");
    _builder.newLine();
    _builder.append("\t\t\t\t\t");
    _builder.append("m2()");
    _builder.newLine();
    _builder.append("\t\t\t\t\t");
    _builder.append("this.m2()");
    _builder.newLine();
    _builder.append("\t\t\t\t\t");
    _builder.append("C.this.m2");
    _builder.newLine();
    _builder.append("\t\t\t\t");
    _builder.append("]");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("interface I {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("def void m1(int i)");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("static class D {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("def void m1(int i) {}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("@SuppressWarnings(\"all\")");
    _builder_1.newLine();
    _builder_1.append("public class C {");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public interface I {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("void m1(final int i);");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public static class D {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("public void m1(final int i) {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public void m1(final String s) {");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public void m2() {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("abstract class __C_1 extends C.D {");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("final __C_1 _this__C_1 = this;");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("public abstract void m2();");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("new __C_1() {");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("public void m2() {");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("final C.I _function = new C.I() {");
    _builder_1.newLine();
    _builder_1.append("          ");
    _builder_1.append("@Override");
    _builder_1.newLine();
    _builder_1.append("          ");
    _builder_1.append("public void m1(final int it) {");
    _builder_1.newLine();
    _builder_1.append("            ");
    _builder_1.append("this.m1(1);");
    _builder_1.newLine();
    _builder_1.append("            ");
    _builder_1.append("_this__C_1.m1(1);");
    _builder_1.newLine();
    _builder_1.append("            ");
    _builder_1.append("_this__C_1.m1(1);");
    _builder_1.newLine();
    _builder_1.append("            ");
    _builder_1.append("C.this.m1(\"\");");
    _builder_1.newLine();
    _builder_1.append("            ");
    _builder_1.append("C.this.m1(\"\");");
    _builder_1.newLine();
    _builder_1.append("            ");
    _builder_1.append("_this__C_1.m2();");
    _builder_1.newLine();
    _builder_1.append("            ");
    _builder_1.append("_this__C_1.m2();");
    _builder_1.newLine();
    _builder_1.append("            ");
    _builder_1.append("C.this.m2();");
    _builder_1.newLine();
    _builder_1.append("          ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("};");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("final C.I i = _function;");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("};");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    this.assertCompilesTo(_builder, _builder_1);
  }
}
